class seq_group_bynum:
    def __init__(self,num):
        self.num=num
        self.data=[]
    def oncalc(self,i,timekey=None):
        if i is not None:
            self.data.append(str(i))
            if len(self.data)==self.num:
                return "".join(self.data)
            elif len(self.data)>self.num:
                self.data.pop(0)
                return "".join(self.data)
            else:
                return None
        else:
            return None
if __name__ == '__main__':
    from jili.core import load, save
    from research.calcor.calcors_graph import graph_calcor
    from research.calcor.dim1.updown import updown
    k1m = load(r"D:\data\k1m_tq\TA109\202105_k1m.pkl")
    updown0=updown()
    seq_group_bynum0=seq_group_bynum(6)
    cc = [{'calc_cmd': 'ta', 'cmd': 'EMA', 'out': ['ema30'], 'input': {'price': 'close'}, 'arg': {'timeperiod': 30},
           'batch': 30},
          {'calc_cmd': 'ta', 'cmd': 'EMA', 'out': ['ema10'], 'input': {'price': 'close'}, 'arg': {'timeperiod': 10},
           'batch': 10},
          {'calc_cmd': 'function', 'function': updown0.oncalc, 'out': ['updown0'], 'input': ["close"]},
          {'calc_cmd': 'function', 'function': seq_group_bynum0.oncalc, 'out': ['code'], 'input': ["updown0"]}
          ]
    c = graph_calcor(cc)
    for d, v in k1m.items():
        for t in v:
            t = c.onbar(t)
    print("end")